function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1
            c_end = document.cookie.indexOf(";", c_start)
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}

function getStatusString (status) {
    var str = new Array("未支付","进行中","已完成","已关闭");
    return str[status];
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date()
    exdate.setDate(exdate.getDate() + expiredays)
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}

function checkCookie() {
    username = getCookie('username')
    if (username != null && username != "") {
        alert('Welcome again ' + username + '!')
    } else {
        username = prompt('Please enter your name:', "")
        if (username != null && username != "") {
            setCookie('username', username, 365)
        }
    }
}

function checkInput(hint,string) {
    if (string.length == 0) {
        alert(hint + ":空")
        return false;
    } else if (string.match(" ")) {
        alert(hint + ":不能包含空格")
        return false;
    } 
    return true;
}

function checkInputEnglish(hint,string) {
    var jgpattern = /^[A-Za-z0-9]+$/;
    if (string.length == 0) {
        alert(hint + ":空")
        return false;
    } else if (string.match(" ")) {
        alert(hint + ":不能包含空格")
        return false;
    } else if (!jgpattern.test(string)) {
        alert(hint + "-" + string + "：只能输入英文字母大小写以及数字")
        return false;
    }
    return true;
}

function checkInputNumber(hint,string) {
    var jgpattern = /^[0-9|.]+$/;
    if (string.length == 0) {
        alert(hint + ":空")
        return false;
    } else if (string.match(" ")) {
        alert(hint + ":不能包含空格")
        return false;
    } else if (!jgpattern.test(string)) {
        alert(hint + "-" + string + "：只能输入数字")
        return false;
    }
    return true;
}

function ajax_package(url,jsonobject,succeed) {
    var settings = {
        type: "POST",
        url: url,
        dataType: "json",
        data: jsonobject,
        error: function(XHR, textStatus, errorThrown) {
            alert("网络错误");
        },
        success: function(data, textStatus) {
            if (textStatus == "success") {
                succeed(data,textStatus);
            }
        },
    };
    return settings;    
}
var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = decodeURIComponent(pair[1]);
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(decodeURIComponent(pair[1]));
    }
  } 
    return query_string;
}();

// generate the uuid in a magic way
var lut = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); }
function generateUUID()
{
    var d0 = Math.random()*0xffffffff|0;
    var d1 = Math.random()*0xffffffff|0;
    var d2 = Math.random()*0xffffffff|0;
    var d3 = Math.random()*0xffffffff|0;
    
    return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
    lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
    lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
    lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff];
}

function getUUID() {
    var uuid = getCookie("device_id");
    if (!uuid) {
        uuid = generateUUID();
        setCookie("device_id",uuid,1);
    }
    return uuid;
}

//需要jQuery
$.fn.extend({
    animateCss: function (animationName, something) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        $(this).addClass('animated ' + animationName).one(animationEnd, function() {
            $(this).removeClass('animated ' + animationName);
            something()
        });
    }
});

toastr.options = {
  "closeButton": false,
  "debug": false,
  "newestOnTop": false,
  "progressBar": false,
  "positionClass": "toast-bottom-full-width",
  "preventDuplicates": false,
  "onclick": null,
  "showDuration": "300",
  "hideDuration": "1000",
  "timeOut": "5000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}
